import { SOpenRechargeInfoEx } from "../../../../Message/Public/SOpenRechargeInfoEx";
import { OpenRechargeGiftBagConfig } from "../../resource/OpenRechargeGiftBagConfig";
import { Cache } from "../../cache/Cache";
import { TOpenRechargeGiftBag } from "../../../../Message/Db/Tables/TOpenRechargeGiftBag";
import { OpenRechargeInfo } from "./OpenRechargeInfo";
import { OpenRechargeType } from "./OpenRechargeType";
type int = number;
//class OpenRechargeDataUtil
    
    export  class OpenRechargeDataUtil
    {
        constructor()
        {
            
            this._dayRecharge = new Map<any, any> /* flash.utils.Dictionary */();
            this._hadGetCodes = [];
            this._openRechargeInfos = [];
            if (OpenRechargeDataUtil._instance) 
            {
                throw new Error("OpenRechargeDataUtil 单例");
            }
            return;
        }

        public set openRechargeInfoEx(arg1: SOpenRechargeInfoEx)
        {
            this._openRechargeInfoEx = arg1;
            if (arg1) 
            {
                this._openDay = arg1.day;
                if (arg1.dayRecharge) 
                {
                    this._dayRecharge = arg1.dayRecharge;
                }
                if (arg1.hadGetCodes) 
                {
                    this._hadGetCodes = arg1.hadGetCodes;
                }
            }
            return;
        }

        public set hadGetCodes(arg1: Array<any>)
        {
            this._hadGetCodes = arg1;
            return;
        }

        public set openRechargeType(arg1: int)
        {
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            var loc7=0;
            var loc8=0;
            this._openRechargeInfos.splice(0);
            var loc1=OpenRechargeGiftBagConfig.instance.getConsumeCountGiftBag(arg1, Cache.instance.role.activeWorldLevel);
            loc1.sortOn("value", Array.NUMERIC);
            if (loc1) 
            {
                loc2 = loc1.length;
                loc6 = 0;
                while (loc6 < loc2) 
                {
                    if (loc3 = loc1[loc6] as TOpenRechargeGiftBag) 
                    {
                        (loc4 = new OpenRechargeInfo()).info = loc3;
                        loc7 = this._dayRecharge[loc3.value];
                        if (loc3.value > this._openDay || this._openDay == 0) 
                        {
                            loc4.openState = OpenRechargeType.OpenRechargeTypeNotOpen;
                        }
                        else 
                        {
                            loc8 = 0;
                            while (loc8 < this._hadGetCodes.length) 
                            {
                                loc5 = this._hadGetCodes[loc8];
                                if (loc3.code == loc5) 
                                {
                                    loc4.openState = OpenRechargeType.OpenRechargeTypeHadGot;
                                    break;
                                }
                                ++loc8;
                            }
                            if (loc4.openState != OpenRechargeType.OpenRechargeTypeHadGot) 
                            {
                                if (loc7 >= loc3.target) 
                                {
                                    loc4.openState = OpenRechargeType.OpenRechargeTypeCanGet;
                                }
                                else if (loc3.value == this._openDay) 
                                {
                                    loc4.openState = OpenRechargeType.OpenRechargeTypeHadOpen;
                                }
                                else 
                                {
                                    loc4.openState = OpenRechargeType.OpenRechargeTypeOverdue;
                                }
                            }
                            loc4.recharge = loc7;
                            if (loc3.value == this._openDay) 
                            {
                                loc4.isOpenDay = true;
                                this._currentOpenInfo = loc4;
                            }
                        }
                    }
                    this._openRechargeInfos.push(loc4);
                    ++loc6;
                }
            }
            return;
        }

        public OpenRechargeDataUtil.get openRechargeInfos(): Array<any>
        {
            return this._openRechargeInfos;
        }

        public OpenRechargeDataUtil.get currentOpenInfo(): OpenRechargeInfo
        {
            return this._currentOpenInfo;
        }

        public static get instance(): OpenRechargeDataUtil
        {
            if (OpenRechargeDataUtil._instance == null) 
            {
                OpenRechargeDataUtil._instance = new OpenRechargeDataUtil();
            }
            return OpenRechargeDataUtil._instance;
        }

        /* internal */ /* var */_openRechargeInfoEx: SOpenRechargeInfoEx;

        /* internal */ /* var */_openDay: int=0;

        /* internal */ /* var */_dayRecharge: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_hadGetCodes: Array<any>;

        /* internal */ /* var */_openRechargeInfos: Array<any>;

        /* internal */ /* var */_currentOpenInfo: OpenRechargeInfo;

        /* internal */ static /* var */_instance: OpenRechargeDataUtil;
    }
